package pers.vic.dubbo.provider.api;

import org.apache.dubbo.config.annotation.DubboService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pers.vic.dubbo.common.api.DubboDemoService;
import pers.vic.dubbo.common.model.VicModel;
import pers.vic.dubbo.common.tool.DubboTools;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 描述:
 * @author Vic.xu
 * @date 2021-12-29 17:09
 */
@DubboService(version = "1.0.0")
public class DubboServiceImpl implements DubboDemoService {

    private Logger logger = LoggerFactory.getLogger(DubboServiceImpl.class);

    @Override
    public VicModel findById(Integer id) {
        printTranceId();
        VicModel model = new VicModel();
        model.setId(id);
        model.setName("zhangsan");
        model.setTime(new Date());
        return model;
    }

    @Override
    public List<VicModel> findList() {
        printTranceId();
        List<VicModel> list = new ArrayList<>();
        list.add(new VicModel(1, "李四", new Date()));
        list.add(new VicModel(2, "王五", new Date()));
        list.add(new VicModel(3, "张三", new Date()));
        return list;
    }

    @Override
    public int deleteById(Integer id) {
        printTranceId();
        return 1;
    }

    private void printTranceId(){
        logger.info("TanceId:" + DubboTools.getLocalTranceId());
    }

}
